/**
 */
package OBSL.impl;

import OBSL.GeneralizationLink;
import OBSL.OBSLPackage;
import OBSL.SubstanceIndividual;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Substance Individual</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link OBSL.impl.SubstanceIndividualImpl#getGeneralization <em>Generalization</em>}</li>
 *   <li>{@link OBSL.impl.SubstanceIndividualImpl#getSpecialization <em>Specialization</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class SubstanceIndividualImpl extends PresentIndividualImpl implements SubstanceIndividual {
	/**
	 * The cached value of the '{@link #getGeneralization() <em>Generalization</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGeneralization()
	 * @generated
	 * @ordered
	 */
	protected GeneralizationLink generalization;

	/**
	 * The cached value of the '{@link #getSpecialization() <em>Specialization</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSpecialization()
	 * @generated
	 * @ordered
	 */
	protected EList<GeneralizationLink> specialization;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SubstanceIndividualImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return OBSLPackage.Literals.SUBSTANCE_INDIVIDUAL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public GeneralizationLink getGeneralization() {
		return generalization;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetGeneralization(GeneralizationLink newGeneralization, NotificationChain msgs) {
		GeneralizationLink oldGeneralization = generalization;
		generalization = newGeneralization;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION, oldGeneralization, newGeneralization);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGeneralization(GeneralizationLink newGeneralization) {
		if (newGeneralization != generalization) {
			NotificationChain msgs = null;
			if (generalization != null)
				msgs = ((InternalEObject)generalization).eInverseRemove(this, OBSLPackage.GENERALIZATION_LINK__SPECIFIC, GeneralizationLink.class, msgs);
			if (newGeneralization != null)
				msgs = ((InternalEObject)newGeneralization).eInverseAdd(this, OBSLPackage.GENERALIZATION_LINK__SPECIFIC, GeneralizationLink.class, msgs);
			msgs = basicSetGeneralization(newGeneralization, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION, newGeneralization, newGeneralization));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<GeneralizationLink> getSpecialization() {
		if (specialization == null) {
			specialization = new EObjectWithInverseResolvingEList<GeneralizationLink>(GeneralizationLink.class, this, OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION, OBSLPackage.GENERALIZATION_LINK__GENERAL);
		}
		return specialization;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION:
				if (generalization != null)
					msgs = ((InternalEObject)generalization).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION, null, msgs);
				return basicSetGeneralization((GeneralizationLink)otherEnd, msgs);
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSpecialization()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION:
				return basicSetGeneralization(null, msgs);
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION:
				return ((InternalEList<?>)getSpecialization()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION:
				return getGeneralization();
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION:
				return getSpecialization();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION:
				setGeneralization((GeneralizationLink)newValue);
				return;
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION:
				getSpecialization().clear();
				getSpecialization().addAll((Collection<? extends GeneralizationLink>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION:
				setGeneralization((GeneralizationLink)null);
				return;
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION:
				getSpecialization().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__GENERALIZATION:
				return generalization != null;
			case OBSLPackage.SUBSTANCE_INDIVIDUAL__SPECIALIZATION:
				return specialization != null && !specialization.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //SubstanceIndividualImpl
